<?

/***************************************************************************
Jupiter Content System @ Jupiterportal.org
 
Copyright (C) 2005-2007 Cosmin Flavius (highstrike@gmail.com)
Copyright (C) 2008-2009 George Mark (gmark@jupiterportal.org)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU 
General Public License as published by the Free Software Foundation; either version 3 of the License, 
or (at your option) any later version.

More Info About The License At http://www.gnu.org/copyleft/gpl.html

****************************************************************************/

ini_set("zlib.output_compression","on");
ini_set("zlib.output_compression_level","9");

//-----------------------------------------------------------------
//  Start up the script
//-----------------------------------------------------------------

session_start();
header("Cache-control: private");
ob_start();

error_reporting (E_ALL);
$PHP_SELF = $_SERVER['PHP_SELF'];

require "includes/config.php";

//-----------------------------------------------------------------
//  Change this website address to your website address.
//  You will also need to go to line 365, and change $smilies_path to reflect your site url
//-----------------------------------------------------------------

$siteurl = "http://www.galiciarol.org/";
$feedfilename = "rss.php";

if(@!mysql_connect($database_server,$database_username,$database_password))
{
	?>
		Couldn't establish link. Reason: <?= mysql_error() ?>
	<?

	exit;
}

//-----------------------------------------------------------------
//  Load WAMIS conformant module - DB
//-----------------------------------------------------------------

require_once("includes/functions_db.php");
DB_initialize();

//-----------------------------------------------------------------
//  Database Check
//-----------------------------------------------------------------

if(!$db->connect())
{ 
	?>
		Error, the database "<?= $database_name ?>" dosen't exist.
	<?

	exit;
} 

//-----------------------------------------------------------------
//  Tabels Check
//-----------------------------------------------------------------

if(!$config_db = $db->query("SELECT * FROM config"))
{ 
	?>
		Error, the database "<?= $database_name ?>" is empty.
	<?

	exit;
}

//-----------------------------------------------------------------
//  Load Config + Misc
//-----------------------------------------------------------------

while ($config_item = mysql_fetch_row($config_db)) $config[$config_item[0]] = $config_item[1];

$misc_db = $db->query("SELECT * FROM misc");
while ($misc_item = mysql_fetch_row($misc_db)) $misc[$misc_item[0]] = $misc_item[1];

//-----------------------------------------------------------------
//  RSS Functions
//-----------------------------------------------------------------

////////////////////////////////////////////////////////
// Description: Notice fix

if(!isset($a)) $a = NULL;	// Action fix
if(!isset($c)) $c = NULL;	// Another Action fix
if(!isset($l)) $l = NULL;	// Poll Action fix
if(!isset($d)) $d = NULL;	// Data fix
if(!isset($o)) $o = NULL;	// Other fix
if(!isset($q)) $q = NULL;	// Another Other fix
if(!isset($k)) $k = NULL;	// Another Another Other fix
if(!isset($i)) $i = NULL;	// Info fix
if(!isset($p)) $p = 1;		// Pagination fix
if(!isset($m)) $m = date('n');	// Calendar fix

if(!isset($action)) $action = NULL;
if(!isset($template_left)) $template_left = NULL;
if(!isset($session_id)) $session_id = session_id();
if(!isset($layout)) $layout = NULL;
if(!isset($layout2)) $layout2 = NULL;
if(!isset($template_right)) $template_right = NULL;
if(!isset($_SERVER['HTTP_REFERER'])) $_SERVER['HTTP_REFERER'] = NULL;
if(!isset($PHP_SELF)) $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
if(!isset($_SESSION['authorization'])) $_SESSION['authorization'] = 0;

////////////////////////////////////////////////////////
// Description: Autoexecute these querys

$badwords_db = $db->getTable("SELECT * FROM badwords");
$emoticons_db = $db->getTable("SELECT * FROM emoticons");

////////////////////////////////////////////////////////
// Function:         jcm_linebreaks
// Description: Convert \r\n and \r to \n

function jcm_linebreaks($str){ return str_replace("\r", "\n", str_replace("\r\n", "\n", $str)); }

////////////////////////////////////////////////////////
// Function:         jcm_stripslashes
// Description: Strip slashes

function jcm_stripslashes($str){ return (get_magic_quotes_gpc() == 1) ? stripslashes($str) : $str; }

////////////////////////////////////////////////////////
// Function:         jcm_strlen
// Description: A more special strlen()

function jcm_strlen($str){ return strlen(preg_replace('/&#([0-9]+);/', '!', $str)); }

////////////////////////////////////////////////////////
// Function:         jcm_htmlspecialchars
// Description: A more special htmlspecialchars()

function jcm_htmlspecialchars($str)
{
	$str = preg_replace('/&(?!#[0-9]+;)/s', '&amp;', $str);
	$str = str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $str);

return $str;
}

function paginate()
{
}

////////////////////////////////////////////////////////
// Function:         split_text
// Description: Split the message into tokens

function split_text($text, $start, $end)
{
	$num_spaces = 4;

	$tokens = explode($start, $text);

	$outside[] = $tokens[0];

	$num_tokens = count($tokens);
	for ($i = 1; $i < $num_tokens; ++$i)
	{
		$temp = explode($end, $tokens[$i]);
		$inside[] = $temp[0];
		$outside[] = $temp[1];
	}

	if ($num_spaces != 8 && $start == '[code]')
	{
		$spaces = str_repeat(' ', $num_spaces);
		$inside = str_replace("\t", $spaces, $inside);
	}

return array($inside, $outside);
}

////////////////////////////////////////////////////////
// Function:         check_tag_order
// Description: Check for [code] and [quote]

function check_tag_order($text,$x)
{
	// The maximum allowed quote depth
	$max_depth = 3;

	while (true)
	{
		$c_start = strpos($text, '[code]');
		$c_end = strpos($text, '[/code]');
		$q_start = strpos($text, '[quote]');
		$q_end = strpos($text, '[/quote]');

		if (preg_match('#\[quote=(&quot;|"|\'|)(.*)\\1\]#sU', $text, $matches)) $q2_start = strpos($text, $matches[0]);
		else $q2_start = 65536;

		if ($c_start === false) $c_start = 65536;
		if ($c_end === false) $c_end = 65536;
		if ($q_start === false) $q_start = 65536;
		if ($q_end === false) $q_end = 65536;

		if (min($c_start, $c_end, $q_start, $q_end, $q2_start) == 65536) break;

		$q3_start = ($q_start < $q2_start) ? $q_start : $q2_start;

		if ($q3_start < min($q_end, $c_start, $c_end))
		{
			$step = ($q_start < $q2_start) ? 7 : strlen($matches[0]);

			$cur_index += $q3_start + $step;

			if ($q_depth == $max_depth) $overflow_begin = $cur_index - $step;

			++$q_depth;
			$text = substr($text, $q3_start + $step);
		}
		else if ($q_end < min($q_start, $c_start, $c_end))
		{
			if ($q_depth == 0){ return $x = 1; exit; }

			$q_depth--;
			$cur_index += $q_end+8;

			if ($q_depth == $max_depth) $overflow_end = $cur_index;

			$text = substr($text, $q_end+8);
		}
		else if ($c_start < min($c_end, $q_start, $q_end))
		{
			$tmp = strpos($text, '[/code]');
			if ($tmp === false){ return $x = 2; exit; }
			else $text = substr($text, $tmp+7);

			$cur_index += $tmp+7;
		}
		else if ($c_end < min($c_start, $q_start, $q_end)){ return $x = 3; exit; }
	}

	if ($q_depth > 0){ return $x = 4; exit; }
	else if ($q_depth < 0){ return $x = 5; exit; }


if (isset($overflow_begin)) return array($overflow_begin, $overflow_end);
else return null;
}

////////////////////////////////////////////////////////
// Function:         truncate_url
// Description: Takes care of url

function truncate_url($url, $link = '')
{
	$full_url = $url;
	if (strpos($url, 'www.') === 0) $full_url = 'http://'.$full_url;
	else if (strpos($url, 'ftp.') === 0) $full_url = 'ftp://'.$full_url;
	else if (strpos($url, 'http://') !== 0) $full_url = 'http://'.$full_url;

	$link = ($link == '' || $link == $url) ? ((strlen($url) > 55) ? substr($url, 0 , 39).' ... '.substr($url, -10) : $url) : stripslashes($link);

return '<a href="'.$full_url.'" target="_blank">'.$link.'</a>';
}

////////////////////////////////////////////////////////
// Function:         handle_img_tag
// Description: Takes care of the image

function handle_img_tag($url)
{
	$img_tag = '<img src="'.$url.'" alt="'.htmlspecialchars($url).'" style="border: none;" />';

	return $img_tag;
}

////////////////////////////////////////////////////////
// Function:         do_bbcode
// Description: Takes care of bbcode

function do_bbcode($message)
{
	$pattern[] = '#\[b\](.*?)\[/b\]#s';
	$pattern[] = '#\[i\](.*?)\[/i\]#s';
	$pattern[] = '#\[u\](.*?)\[/u\]#s';
	$pattern[] = '#\[font=(.*?)\](.*?)\[/font\]#s';
	$pattern[] = '#\[size=(.*?)\](.*?)\[/size\]#s';
	$pattern[] = '#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#s';
	$pattern[] = '#\[left\](.*?)\[/left\]#s';
	$pattern[] = '#\[center\](.*?)\[/center\]#s';
	$pattern[] = '#\[right\](.*?)\[/right\]#s';
	$pattern[] = '#\[list\]#s';
	$pattern[] = '#\[/list\]#s';
	$pattern[] = '#\[\*\]#s';
	$pattern[] = '#\[image=((ht|f)tps?://)([^\s<"]*?)\\]#e';
	$pattern[] = '#\[url\](.*?)\[/url\]#e';
	$pattern[] = '#\[url=(.*?)\](.*?)\[/url\]#e';
	$pattern[] = '#\[email\](.*?)\[/email\]#';
	$pattern[] = '#\[email=(.*?)\](.*?)\[/email\]#';

	$replace[] = '<strong>$1</strong>';
	$replace[] = '<em>$1</em>;';
	$replace[] = '<u>$1</u>;';
	$replace[] = '<span style="font-family: $1;">$2</span>';
	$replace[] = '<span style="font-size: $1;">$2</span>';
	$replace[] = '<span style="color: $1;">$2</span>';
	$replace[] = '<div style="text-align: left;">$1</div>';
	$replace[] = '<div style="text-align: center;">$1</div>';
	$replace[] = '<div style="text-align: right;">$1</div>';
	$replace[] = '<ul>';
	$replace[] = '</ul>';
	$replace[] = '<li>';
	$replace[] = 'handle_img_tag(\'$1$3\')';
	$replace[] = 'truncate_url(\'$1\')';
	$replace[] = 'truncate_url(\'$1\', \'$2\')';
	$replace[] = '<a href="mailto:$1">$1</a>';
	$replace[] = '<a href="mailto:$1">$2</a>';


	// This thing takes a while! :)
	$message = preg_replace($pattern, $replace, $message);

	if (strpos($message, 'quote') !== false)
	{
		$message = preg_replace('#\[quote=(&quot;|"|\'|)(.*)\\1\]#seU', '"<h4>Quote: ".str_replace(\'[\', \'&#91;\', \'$2\')."</h4><div style=\"border: 1px solid #999; padding: 10px; font-size: 12px;\">"', $message);
		$message = str_replace('[quote]', '<h4>Quote</h4><div style="border: 1px solid #999; padding: 10px; font-size: 12px;">', $message);
		$message = str_replace('[/quote]', '</div>', $message);
	}

return $message;
}

////////////////////////////////////////////////////////
// Function:         do_clickable
// Description: Takes care of links

function do_clickable($message)
{
	$message = ' '.$message;

	$message = preg_replace('#([\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.truncate_url(\'$2://$3\')', $message);
	$message = preg_replace('#([\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.truncate_url(\'$2.$3\', \'$2.$3\')', $message);

return substr($message, 1);
}

////////////////////////////////////////////////////////
// Function:         do_smilies
// Description: Takes care of emoticons

function do_smilies($message)
{
	global $emoticons_db;

	if($emoticons_db != FALSE)
	{
		$smilies_path = "http://www.jupiterportal.org/images/emoticons";
		foreach($emoticons_db as $idx=>$emoticons)
		{
			$smiley_codes[] = $emoticons['code'];
			$smiley_files[] = $emoticons['pic'];
		}

		$message = ' '.$message.' ';

		for ($count = 0; $count <= $idx; $count++) 
			$message = preg_replace("#(?<=.\W|\W.|^\W)".preg_quote($smiley_codes[$count], '#')."(?=.\W|\W.|\W$)#m", '$1<img src="'.$smilies_path.'/'.$smiley_files[$count].'" alt="'.$smiley_codes[$count].'" />$2', $message);

		return substr($message, 1, -1);
	}
	else return $message;
}

////////////////////////////////////////////////////////
// Function:         do_censor
// Description: Takes care of badwords

function do_censor($message)
{
	global $config, $badwords_db;

	if($badwords_db != FALSE)
	{
		foreach($badwords_db as $idx=>$badwords)
		{
			$badword[] = $badwords['word'];
			$wordreplacment[] = $badwords['replacement'];
		}

		$message = ' '.$message.' ';
	
		for ($count = 0; $count <= $idx; $count++)
		{
			if($config['badword_mode'] == 1) $message = preg_replace ( '#'.$badword[$count].'#i', ''.$wordreplacment[$count].'', $message );
			else $message = preg_replace ( '#'.$badword[$count].'#i', str_pad ( '', strlen ( $badword[$count] ), '*' ), $message );
		}

		return substr($message, 1, -1);
	}
	else return $message;
}

////////////////////////////////////////////////////////
// Function:         parse_char
// Description: Replaces charactars + adds bb and sm

function parse_message($message)
{
	global $config;

	$message = jcm_htmlspecialchars($message);

	if (strpos($message, '[url]') !== false && strpos($message, '[/url]') !== false)
		$message = cuttext($message,115);

	if (strpos($message, '[code]') !== false && strpos($message, '[/code]') !== false)
	{
		list($inside, $outside) = split_text($message, '[code]', '[/code]');
		$outside = array_map('trim', $outside);
		$message = implode('<">', $outside);
	}

	if ($config['badwords'] == 1)
		$message = do_censor($message);

	$message = do_clickable($message);

	if ($config['emoticons'] == 1)
		$message = do_smilies($message);

	if ($config['bbcode'] == 1 && strpos($message, '[') !== false && strpos($message, ']') !== false)
		$message = do_bbcode($message);

	$pattern = array("\n", "\t", '  ', '  ');
	$replace = array('</p><p>', '&nbsp; &nbsp; ', '&nbsp; ', ' &nbsp;');
	$message = str_replace($pattern, $replace, $message);

	if (isset($inside))
	{
		$outside = explode('<">', $message);
		$message = '';

		$num_tokens = count($outside);

		for ($i = 0; $i < $num_tokens; $i++)
		{
			$message .= $outside[$i];
			if (isset($inside[$i])) $message .= '<h4>Code:</h4><div style="border: 1px solid #999; padding: 10px; font-size: 12px;">'.trim($inside[$i]).'</div>';
		}
	}

return $message;
}

////////////////////////////////////////////////////////
// Function:         dis_bb_em
// Description: Status on BBcode and Emoticons Global

function dis_bb_em($ex=false)
{
	global $config;
	require "language/{$config['language']}";

	if($config['bbcode'] == 1) $bbcode = "<span class='ok'>{$language['Enabled']}</span>";
	else $bbcode = "<span class='alert'>{$language['Disabled']}</span>";

	if($config['emoticons'] == 1) $emoticons = "<span class='ok'>{$language['Enabled']}</span>";
	else $emoticons = "<span class='alert'>{$language['Disabled']}</span>";

	if($config['badwords'] == 1) $badwords = "<span class='ok'>{$language['Enabled']}</span>";
	else $badwords = "<span class='alert'>{$language['Disabled']}</span>";

	if($ex == "true") $spaces = "<br><br><br><br><br><br>";
	else $spaces = "<br><br><br>";

	$output = "$spaces<a href='?n=modules/misc&a=2'>{$language['BBcode']}</a> > $bbcode<br><a href='?n=modules/misc&a=3'>{$language['Emoticons']}</a> > $emoticons<br><a href='?n=modules/misc&a=4'>{$language['Badwords']}</a> > $badwords";

return $output;
}

////////////////////////////////////////////////////////
// Function:         insertBBcode
// Description: insert bbcode

function insertBBcode($break_location = FALSE)
{
	global $config;
	require "language/{$config['language']}";

	$bbcodes_path = "templates/{$config['template']}/images/codes";
	$bbcode_codes = array("[b]Text[/b]","[i]Text[/i]","[u]Text[/u]","[font=verdana]Text[/font]","[size=2]Text[/size]","[color=red]Text[/color]","[left]text[/left]","[center]text[/center]","[right]text[/right]","[list][*]Text1[*]Text2[/list]","[quote=Name]Text[/quote]","[code]Text[/code]","[image=URL]","[url=URL]Text[/url]","[email=URL]Text[/email]");
	$bbcode_files = array("bold.gif","italic.gif","underline.gif","fontface.gif","fontsize.gif","color.gif","fontleft.gif","fontcenter.gif","fontright.gif","list.gif","quote.gif","code.gif","img.gif","url.gif","email.gif");
	$bbcode_alt = array($language['BBcode desc'],$language['BBcode desc2'],$language['BBcode desc3'],$language['BBcode desc4'],$language['BBcode desc5'],$language['BBcode desc6'],$language['BBcode desc7'],$language['BBcode desc8'],$language['BBcode desc9'],$language['BBcode desc10'],$language['BBcode desc11'],$language['BBcode desc12'],$language['BBcode desc13'],$language['BBcode desc14'],$language['BBcode desc15']);

	foreach($bbcode_codes as $idx=>$code)
	{
		if(!isset($h)) $h = 1;
		if(!isset($output)) $output = NULL;

		if($config['bbcode'] == 1) $output .="<a href=\"Javascript:insertext('$code')\"><img style=\"border: none;\" src=\"$bbcodes_path/{$bbcode_files[$idx]}\" alt=\"{$bbcode_alt[$idx]}\"></a>";
		else $output .="<img style=\"border: none;\" src=\"$bbcodes_path/{$bbcode_files[$idx]}\" alt=\"{$language['Disabled']}\">";

		if($h % $break_location == 0 and $break_location) $output .= "<br>";
		else $output .= "";

		$h++;
	}

return $output;
}

////////////////////////////////////////////////////////
// Function:         insertSmilies
// Description: insert smilies

function insertSmilies($break_location = FALSE)
{
	global $config, $emoticons_db;
	require "language/{$config['language']}";

	$smilies_path = "images/emoticons";

	if($emoticons_db != FALSE)
	{
		foreach($emoticons_db as $emoticons)
		{
			$smiley_codes[] = $emoticons['code'];
			$smiley_files[] = $emoticons['pic'];
		}

		foreach($smiley_codes as $idx=>$code)
		{
			if(!isset($h)) $h = 1;
			if(!isset($output)) $output = NULL;

			if($config['bbcode'] == 1) $output .="<a href=\"Javascript:insertext('$code')\"><img style=\"border: none;\" src=\"$smilies_path/{$smiley_files[$idx]}\" alt=\"{$smiley_codes[$idx]}\"></a>";
			else  $output .="<img style=\"border: none;\" src=\"$smilies_path/{$smiley_files[$idx]}\" alt=\"{$language['Disabled']}\">";

			if($h % $break_location == 0 and $break_location) $output .= "<br>";
			else $output .= "";

			$h++;
		}
	}
	else $output = $language['No Emoticons'];

return $output;
}

////////////////////////////////////////////////////////
// Function:         cuttext
// Description: Cuts a string and adds ..

function cuttext($value,$lenght)
{
	if (strlen($value) >= $lenght )
	{
		$limited = substr($value,0,$lenght);
		$limited .= "...";                 
	}
	else
		$limited = $value;

return $limited;
}

////////////////////////////////////////////////////////
// Function:         today_yesterday
// Description: Function for Today and Yesterday

function today_yesterday($time,$ex=false)
{
	global $config;
	require "language/{$config['language']}";

	$today = date("d/m/y",time());
	$yesterday = date("d/m/y",time() - 86400);

	if($ex == "true")
	{
		if ($today == date("d/m/y",$time)) $date = "{$language['Time today']} ".date("h:i:s A", $time)."";
		elseif ($yesterday == date("d/m/y",$time)) $date = "{$language['Time yesterday']} ".date("h:i:s A", $time)."";
		else $date = date("d/m/y h:i:s A", $time);
	}
	else
	{
		if ($today == date("d/m/y",$time)) $date = "{$language['Time today']} - ".date("h:i:s A", $time)."";
		elseif ($yesterday == date("d/m/y",$time)) $date = "{$language['Time yesterday']} - ".date("h:i:s A", $time)."";
		else $date = date("d/m/y - h:i:s A", $time);
	}

return $date;
}

//-----------------------------------------------------------------
//  Language check + Default Overcheck
//-----------------------------------------------------------------

global $sitelanguage;
if(!file_exists("language/$sitelanguage.php"))
{
	if(!isset($_SESSION['no_language']))
	{
		?>
			Error, the language file <?= $config['language'] ?> dosen't exist.
		<?

		$_SESSION['no_language'] = 1;

		exit;
	}

	if(isset($_SESSION['no_language']))
	{
		if(!file_exists("language/en.php"))
		{
			?>
	Error, no language file, could be found.

			<?

			exit;
		}
		else
		{
			$config['language'] = "en.php";
			require "language/{$config['language']}";
			$db->updateRow("config",array('value' => 'en.php'),"variable = 'language'");
		}
	}
}
else require "language/$sitelanguage.php";

//-----------------------------------------------------------------
//  Maintance Mode Check
//-----------------------------------------------------------------

if($config['maintance'] == 1 && !isset($is_webmaster))
{
	?>
		Maintance Mode has been activated, website is locked down.
	<?

	if(isset($n)) if($n == "modules/login") include("modules/login.php");

	if(!isset($is_loged_in))
	{
		?>
		Maintance Mode has been activated, website is locked down.
		<?
	}
	else
	{
		?>
		Maintance Mode has been activated, website is locked down.
		<?
	}

	exit;
}

$output = "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?".">
            <rss version=\"2.0\">
                <channel>
                <title>{$config['website_name']}</title>
				<description>Site Powered by Jupiter CMS.</description>
				<link>{$siteurl}{$feedfilename}</link>
                ";
			
echo $output;

//-----------------------------------------------------------------
//  Find News Thread
//-----------------------------------------------------------------

$forum_find_news = $db->getLine("SELECT id, cat FROM forum_subcat WHERE type = '2'");

if($forum_find_news != FALSE)
{
	//-----------------------------------------------------------------
	//  Navigation Stuff
	//-----------------------------------------------------------------

	$rows_per_page = $config['nav_news'];
	$numrows = $db->getInfo_countRows("forum_topics","cat = '{$forum_find_news['cat']}' AND subcat = '{$forum_find_news['id']}'");

	$lastpage = ceil($numrows/$rows_per_page);
	$p = (int)$p;

	if ($p < 1) $p = 1;
	elseif ($p > $lastpage) $p = $lastpage;

	if($numrows != FALSE) $limit = 'LIMIT ' .($p - 1) * $rows_per_page .',' .$rows_per_page;
	else $limit = NULL;

	//-----------------------------------------------------------------
	//  Get Database
	//-----------------------------------------------------------------

	$forum_topics = $db->getTable("
	
	SELECT		t.id as tid, t.name, t.cat, t.subcat, t.views,
				r.id as rid, r.topic, r.user_id, r.user_user, r.date, r.message, COUNT(r.id) AS replies,
				u.id AS uid, u.avatar, u.authorization, u.username 
				
	FROM forum_topics AS t 
	LEFT JOIN forum_replies AS r ON (r.topic = t.id)
	LEFT JOIN users AS u ON (r.user_id = u.id AND r.user_user = u.username) 
	
	WHERE t.cat = '{$forum_find_news['cat']}' AND t.subcat = '{$forum_find_news['id']}' AND r.id < '10000000000'
	GROUP BY t.id
	ORDER BY 'tid' DESC $limit");

	//-----------------------------------------------------------------
	//  Start display
	//-----------------------------------------------------------------

	if($forum_topics != FALSE)
	{
		foreach($forum_topics as $idx=>$forum_topic)
		{
			//-----------------------------------------------------------------
			//  Count for ID + trick
			//-----------------------------------------------------------------

			$idx_count = str_replace("-", "", $idx + (($p - 1) * $rows_per_page + 1) - $numrows - 1);

			//-----------------------------------------------------------------
			//  Show some HTML
			//-----------------------------------------------------------------

			?>
						<item>
							<title><?= $forum_topic['name'] ?></title>
							<author>

Posted by <?= $forum_topic['user_user'] ?></author>
							<description><![CDATA[<?= parse_message($forum_topic['message']) ?>]]></description>
							<link><?= $siteurl ?>index.php?n=modules/forum&amp;a=3&amp;d=<?= $forum_topic['cat'] ?>&amp;o=<?= $forum_topic['subcat'] ?>&amp;q=<?= $forum_topic['tid'] ?></link>
							<guid><?= $siteurl ?>index.php?n=modules/forum&amp;a=3&amp;d=<?= $forum_topic['cat'] ?>&amp;o=<?= $forum_topic['subcat'] ?>&amp;q=<?= $forum_topic['tid'] ?></guid>	
						</item>				
			<?

			//-----------------------------------------------------------------
			//  Start from 1
			//-----------------------------------------------------------------

			$idx++;
		}
	}
	else
	{
		//-----------------------------------------------------------------
		//  Reset to 0
		//-----------------------------------------------------------------

		$idx = 0;

		echo "{$language['News view desc6']}";
	}

	//-----------------------------------------------------------------
	//  Navigation Code
	//-----------------------------------------------------------------

	if($p == 1) $nav_prev = "";
	else
	{
		$prevpage = $p-1;
		$nav_prev = "";
	}

	$nav_nr = '[ '.paginate($lastpage, $p, $PHP_SELF.'?n=modules/news').' ]';

	if($idx == $numrows) $nav_nr = NULL;

	if($p == $lastpage) $nav_next = "";
	else
	{
		$nextcode = $numrows - $idx * $p;
		if($nextcode > $idx) $how_next = $idx;
		else $how_next = $nextcode;

		$nextpage = $p+1;

		$nav_next = "";
	}

	if($idx == $numrows)
	{
		$nav_head = "class='con1'";
		$nav = NULL;
	}
	else
	{
		$nav_head = "class='head'";
		$nav = ''.$nav_prev.''.$nav_next.'';
	}

	//-----------------------------------------------------------------
	//  Navigation Display
	//-----------------------------------------------------------------

	?>
		
	<?
}
else echo "{$language['News view desc7']}";

ob_end_flush();
DB_shutdown();

?>
				</channel>
			</rss>